import { Types, defineComponent } from '$lib/ecs';
import { registerAction } from './actions';
import { Stored } from './inventory';
import { decode } from './util';
import { log } from './log';

const MAX_SIZE = 1024;

export const Note = defineComponent('Note', {
  text: [Types.ui8, MAX_SIZE],
});

export const ReadAction = (note) => (world, e) => {
  return {
    error: false,
    action: () => {
      log('The note reads:');
      log(decode(Note.text[note]));
    }
  };
};

registerAction([Note, Stored], 'read', ReadAction);
